int cmp(int* x, int* y)
{
    return *x - *y;
}

int* relativeSortArray(int* arr1, int arr1Size, int* arr2, int arr2Size, int* returnSize) {
    int* a = (int*)malloc(sizeof(int) * arr1Size);
    int n = 0;
    for (int i = 0; i < arr2Size; i++)
    {
        for (int j = 0; j < arr1Size; j++)
        {
            if (arr1[j] == arr2[i])
            {
                a[n++] = arr1[j];
                arr1[j] = 1001;
            }
        }
    }
    qsort(arr1, arr1Size, sizeof(int), cmp);

    for (int i = 0; i < arr1Size; i++)
    {
        if (arr1[i] != 1001)
            a[n++] = arr1[i];
    }
    *returnSize = n;
    return a;
}